<?php
namespace app\api\controller;

use app\api\model\Respont;
use app\api\model\ThirdAPI;
use think\Controller;

class Index
{
    protected  $obj ;
    protected  $user ;
    protected  $fromName ;
    protected  $msgType ;
    protected  $event ;

    public function __construct()
    {

        $this->obj =simplexml_load_string($GLOBALS['HTTP_RAW_POST_DATA']);
        $this->user = $this->obj->FromUserName ;
        $this->fromName= $this->obj->ToUserName ;
        $this->msgType = $this->obj ->MsgType ;
        $this->event   = $this->obj->event?$this->obj->event:null ;
    }


    public function index()
    {
        $msgType = $this->msgType ;
        $event   = $this->event ;
        //回复文本信息
        if($msgType=='text'){
            $this->text_reply();
        }
        //回复地理信息
        if($msgType == 'location'){
            $this->return_text();
        }
        if($msgType == 'event'&&$event =='subscribe'){
            $this->return_text();
        }
        //订阅事件回复
        if($msgType == 'event'&&$event =='subscribe'){
            $this->return_text();
        }
        //扫码事件回复
        if($msgType == 'event'&&$event =='subscribe'){
            $this->return_text();
        }
        //自定义菜单事件回复
        if($msgType == 'event'&&$event =='subscribe'){
            $this->return_text();
        }
     }
    public function test(){
       echo (new ThirdAPI())->id_card('36072619940219435x');
    }
    protected function text_reply(){

        $content = (string)$this->obj->Content ;
        $data = (new ThirdAPI())->id_card($content);
        echo (new Respont($this->obj))->text_return($data);

    }
}


